package Creational

import (
	"fmt"
	"sync"
)

type Singleton struct {
	name string
}

// go 里面没有静态变量，只能使用全局变量代替
var instance *Singleton
var once sync.Once

func NewSingleton(name string) *Singleton {
	once.Do(func() {
		instance = &Singleton{
			name: name,
		}
	})

	return instance
}

func (solo *Singleton) PrintName() {
	fmt.Println(solo.name)
}
